<?php
namespace app\payqr\controller;
use app\BaseController;
use think\App;
use think\facade\Db;
use app\payqr\model\PayQrRecord;

class IndexPayResunt extends BaseController
{


    protected $_config = [];

    public function __construct(App $app) {
        parent::__construct($app);

    }
    /**
     * User: chenniang
     * Date: 2019-09-10 10:09
     * @param string $arr
     * @param string $transaction_id
     * @return bool
     * descption:支付回调
     */
    public function qr_notify($arr,$transaction_id){
        $record = new PayQrRecord();
        $order  = $record->getinfo(['out_trade_no' => $arr['out_trade_no']]);
        if ( !$order || $order[ 'pay_status' ] != 0 ) {
            return false;
        }
        $res = $record->upsave(['id'=>$order['id']],['pay_status'=>1,'transaction_id'=>$transaction_id]);
        if($arr['is_first']){
            $message['content'] = '消费金额'.$arr['money'];
        }else{
            $message['content'] = '消费金额'.$order['money'];
        }
        $message['user_id'] = $order['staff_id'];
        $message['target_id'] = $order['staff_id'];
        $message['uniacid'] = $order['uniacid'];
        $message['create_time'] = time();
        $push_data = array(
            'action'  => 'sendMessageWxServiceNotice',
            'event'   => 'longbingSendMessageWxServiceNotice',
            'message' => $message
        );
        publisher(json_encode($push_data ,true));
        return $res;
    }



}
